{% extends "base.html" %}
{% block title %}{% endblock %}
{% block content %}
<br>
<div class="layui-body" style="overflow:auto;left:1px">
    <form class="layui-form" action="" id="cross_srh">
        <div class="layui-input-inline">
            <label class="layui-form-label">项目*：</label>
            <div class="layui-input-inline">
                <select class="layui-select" name="project_name" id="project_name" lay-verify="" lay-search
                        lay-filter="project_name">
                    <option value="">请选择</option>
                    {% for d in projectAll %}
                    <option value="{{d.id}}">{{d.project_name}}</option>
                    {% endfor %}
                </select>
            </div>
        </div>
        <div class="layui-input-inline" id="project_version_div">
            <label class="layui-form-label">执行任务：</label>
            <div class="layui-input-inline">
                <div id="project_version" style="width: 212px"></div>
            </div>
        </div>

        <div class="layui-input-inline" style="float:right;float:2px">
            <button class="layui-btn  layui-btn-danger" type="button" id="start" lay-submit
                    lay-filter="start">查询
            </button>
        </div>

    </form>

    <hr class="layui-bg-gray">
    <table class="layui-hide" id="hisResultSys" lay-filter="hisResultSys"></table>
    <div id="all" style="height:380px;"></div>

</div>
<script>
    layui.use(['table','element','xmSelect'], function(){
          var table = layui.table
          ,form = layui.form;
          var $= layui.jquery;
          var xmSelect = layui.xmSelect;
          var element = layui.element;
          //根据项目，在结果表中查询所有的执行任务
          $("#project_version_div").show();

          var  options = {
                elem:'#hisResultSys',
                skin:"line",
                page:false,
                //height: 'full-200',
                toolbar: true,
                limit:100,
                limits:[100,500,1000],
                response:{
                    statusName:'errorCode',
                    statusCode:'',
                    dataName:'data'
                },
                id:"hisResultSys",
                cols:[[
                       {type: 'numbers',title:'No.'},
                       ,{field: 'main_moudle', title: '主模块',sort:true}
                       ,{field: 'PASS', title: 'PASS',sort:true}
                       ,{field: 'FAIL', title: 'FAIL',sort:true}
                       ,{field: 'BLOCK', title: 'BLOCK',sort:true}
                       ,{field: 'NT', title: 'NT',sort:true}
                       ,{field: 'total', title: 'total',sort:true}
                       ,{field: 'FailRate', title: '失败率',sort:true, templet: function (d) {

                            return '<span style="color:red">'+d.FailRate+'%</span>';
                       }},{field: 'PassRate', title: '通过率',sort:true, templet: function (d) {
                            return '<span style="color:green">'+d.PassRate+'%</span>';
                       }}
                       ,{field: 'main_process', align:'center',title: '执行进度', templet: function (d) {
                          return '<div class="layui-progress layui-progress-big" lay-showPercent="yes">'+
                                '<div class="layui-progress-bar layui-bg-blue" lay-percent="'+d.main_process+'%"></div></div>';

                       }}

                     ]]
                ,data:[]
                ,done:function(res,cur,count){
                    element.render('main_process');
                    var avg_myChart = echarts.init(document.getElementById('all'));
                    data = table.cache.hisResultSys;

                    var rarray = new Array();
                    layui.each(data,function(k,v){
                        rarray.push({"product":v.main_moudle,"FAIL":v.FAIL,"PASS":v.PASS,"BLOCK":v.BLOCK,"NT":v.NT});
                    });
                    if(rarray.length==0){
                        return false;
                    }

                    chart_option = {
                        legend: {},
                        tooltip: {},
                        dataset: {
                            dimensions: ['product', 'FAIL', 'PASS', 'BLOCK','NT'],
                            source:rarray
                        },
                        xAxis: {type: 'category'},
                        yAxis: {},
                        series: [
                            {type: 'bar'},
                            {type: 'bar'},
                            {type: 'bar'},
                            {type: 'bar'}
                        ]
                    };
                    avg_myChart.setOption(chart_option);
                    form.render();
                }
          }
          var tableIns = table.render(options);

          form.on('submit(start)', function(obj){

                if(obj.field.project_name == "" || obj.field.project_version == ""){
                    layer.msg("项目、执行任务不能为空!");
                    return false;
                }
                var loading = layer.load();
                options = {
                    elem:'#hisResultSys',
                    skin:"line",
                    page:false,
                    url:'/basecase/case/hisResult/sys/byMod?',
                    //height: 'full-200',
                    toolbar: true,
                    limit:100,
                    limits:[100,500,1000],
                    where:{
                        project_version : obj.field.project_version,
                        project_id : $('#project_name option:selected').val(),
                    }
                  }
                tableIns.reload(options);
                layer.close(loading);


          });



          form.on('select(project_name)', function(obj){
                $("#project_version_div").show();
                $.ajax({
                   //发出请求
                   type:"GET",
                   url:"/basecase/case/result/allDoVersion?",
                   contentType: 'application/json; charset=utf-8',
                   dataType:"json",
                   data:{"project_id":obj.value},
                   success: function(result){
                        var casePlanArray = new Array();
                        layui.each(result.data,function(k,v){
                            casePlanArray.push({"name":v.project_version,"value":v.project_version});

                        });
                        var case_module = xmSelect.render({
                              el: '#project_version',
                              name:'project_version',
                              data: casePlanArray
                        });
                        form.render();
                   }
                });

          });

          form.render();
    });

</script>
{% endblock %}